<template>
	<view class="coupon-content">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed customBack :bottomShadow="false" backgroundColor="#FFFFFF00">
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left-arrow' style="color: #fff;"></text>
			</view>
			<view class="tn-flex tn-flex-col-center tn-flex-row-center ">
				<text class="tn-text-bold tn-text-xl tn-color-white"></text>
			</view>
		</tn-nav-bar>
		
		<image :src="webURL+'/static/images/mall/coupon/banner_coupon.png'" mode="widthFix" class="tui-coupon-banner">
		</image>
		
		<view class="tui-coupon-list">
			<view class="tui-coupon-item tui-top20" v-for="(item,index) in couponMenuList" :key="index">
				<image :src="webURL+'/static/images/mall/coupon/bg_coupon_3x.png'" class="tui-coupon-bg"
					mode="widthFix"></image>
				<view class="tui-coupon-item-left">
					<view class="tui-coupon-price-box">
						<view class="tui-coupon-price-sign" v-if="item.type=='reduce'">￥</view>
						<!--tui-price-small 面值>4位数的时候为true-->
						<view class="tui-coupon-price">{{ item.amount }}</view>
						<view class="tui-coupon-price-sign" v-if="item.type == 'discount'">折</view>
					</view>
					<view class="tui-coupon-intro">满{{item.enough}}元可用</view>
				</view>
				<view class="tui-coupon-item-right">
					<view class="tui-coupon-content">
						<view class="tui-coupon-title-box">
							<view class="tui-coupon-btn" :class="{'tui-bg-grey':index>2}">{{item.type_text}}</view>
							<!-- <view class="tui-coupon-title">全部商品可用</view> -->
						</view>
						<view class="tui-coupon-rule">
							<view class="tui-rule-box tui-padding-btm">
								<view class="tui-coupon-circle"></view>
								<view class="tui-coupon-text">不可叠加使用</view>
							</view>
						
							<view class="tui-rule-box">
								<view class="tui-coupon-circle"></view>
								<view class="tui-coupon-text">{{item.description}}</view>
							</view>
							<view class="tui-rule-box">
								<view class="tui-coupon-circle"></view>
								<view class="tui-coupon-text"> {{item.type === 'user'? '有效期：' + item.use_start_time.substring(0, 11): '领取时间：' + item.get_start_time.substring(0, 11)}}至{{ item.type === 'user'? item.use_end_time.substring(0, 11): item.get_end_time.substring(0, 11)}}</view>
							</view>
						</view>
					</view>
				</view>
				<view class="tui-btn-box">
					<tn-button style="width: 150rpx;" v-if="item.get_status != 'can_get'" :disabled="item.get_status != 'can_get'" shape="round" backgroundColor="#ad9d95" fontColor="#fff" :fontSize="22">{{item.get_status_text}}</tn-button>
					<tn-button style="width: 150rpx;" v-else  @click="getBuy(item.id)" shape="round" backgroundColor="#eb0909" fontColor="#fff" :fontSize="22">{{item.get_status_text}}</tn-button>
				</view>
				
			</view>
			

		</view>
	
	</view>
</template>

<script>
	import {
		getCoupon,
		getShopCoupon
		
	} from '../../../apis/index.js'
	export default {
		data() {
			return {
				loadding: false,
				pullUpOn: true,
				couponList: [1, 2, 3, 4, 5],
				webURL: "https://www.thorui.cn/wx",
				couponMenuList: [],
				last_page:null,
				page:1,
				list_rows:10
			}
		},
		onShow() {
			this.couponLists()
		},
		methods: {
			//优惠券领取
			async getBuy(id){
				 const { code, msg } = await getShopCoupon(id)
				if (code === 1) {
				  uni.showToast({
				    title: msg,
				  });
				  setTimeout(() => {
				      this.couponLists();
				    getData();
				  }, 1000);
				  
				}
			},
			//优惠券
			async couponLists() {
				let res = await getCoupon(this.page,this.list_rows)
				// this.couponMenuList = res.data.data
				this.couponMenuList=[...this.couponMenuList,...res.data.data]
				this.last_page=res.data.last_page
			},
			goBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			getSignUrl: function(index) {
				let url = "";
				if (index === 1) {
					url = "https://oss.taoding1688.com/static/uniapp/static/images/mall/coupon/img_couponcentre_received_3x.png"
				} else if (index == 3) {
					url = "https://oss.taoding1688.com/static/uniapp/static/images/mall/coupon/img_coupon_beused_3x.png"
				} else if (index >= 4) {
					url = "https://oss.taoding1688.com/static/uniapp/static/images/mall/coupon/img_coupon_failure_3x.png"
				}
				return url
			}
		},
		onPullDownRefresh() {
			setTimeout(() => {
				this.pullUpOn = true
				uni.stopPullDownRefresh()
			}, 200);
		},
		async onReachBottom() {
			if (this.last_page>=this.page) {
				this.page+=1
				await this.couponLists()
			}
			
			
			
			//只是测试效果，逻辑以实际数据为准
			// if (!this.pullUpOn) return;
			// this.loadding = true
			// setTimeout(() => {
			// 	this.loadding = false
			// 	this.pullUpOn = false
			// }, 1000)
		}
	}
</script>

<style lang="scss" scoped>
	
	.card{
		color: #000;
	}
	page {
		background-color: #F5F5F5;
	}

	.container {
		padding-bottom: env(safe-area-inset-bottom);
	}

	.tui-coupon-list {
		width: 100%;
		padding: 0 25rpx;
		box-sizing: border-box;
	}

	.tui-coupon-banner {
		width: 100%;
	}

	.tui-coupon-item {
		width: 100%;
		height: 210rpx;
		position: relative;
		display: flex;
		align-items: center;
		padding-right: 30rpx;
		box-sizing: border-box;
		overflow: hidden;
	}

	.tui-coupon-bg {
		width: 100%;
		height: 210rpx;
		position: absolute;
		left: 0;
		top: 0;
		z-index: 1;
	}

	.tui-coupon-sign {
		height: 110rpx;
		width: 110rpx;
		position: absolute;
		z-index: 9;
		top: -30rpx;
		right: 40rpx;
	}

	.tui-coupon-item-left {
		width: 218rpx;
		height: 210rpx;
		position: relative;
		z-index: 2;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
		flex-shrink: 0;
	}

	.tui-coupon-price-box {
		display: flex;
		color: #e41f19;
		align-items: flex-end;
	}

	.tui-coupon-price-sign {
		font-size: 30rpx;
	}

	.tui-coupon-price {
		font-size: 56rpx;
		line-height: 68rpx;
		font-weight: bold;
	}

	.tui-price-small {
		font-size: 58rpx !important;
		line-height: 56rpx !important;
	}


	.tui-coupon-intro {
		background: #F7F7F7;
		padding: 8rpx 10rpx;
		font-size: 26rpx;
		line-height: 26rpx;
		font-weight: 400;
		color: #666;
		margin-top: 18rpx;
	}

	.tui-coupon-item-right {
		flex: 1;
		height: 210rpx;
		position: relative;
		z-index: 2;
		display: flex;
		align-items: center;
		justify-content: space-between;
		padding-left: 24rpx;
		box-sizing: border-box;
		overflow: hidden;
	}

	.tui-coupon-content {
		width: 82%;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.tui-coupon-title-box {
		display: flex;
		align-items: center;
	}

	.tui-coupon-btn {
		padding: 6rpx;
		background: #FFEBEB;
		color: #e41f19;
		font-size: 25rpx;
		line-height: 25rpx;
		display: flex;
		align-items: center;
		justify-content: center;
		transform: scale(0.9);
		transform-origin: 0 center;
		border-radius: 4rpx;
		flex-shrink: 0;
	}

	.tui-color-grey {
		color: #888 !important;
	}

	.tui-bg-grey {
		background: #F0F0F0 !important;
		color: #888 !important;
	}

	.tui-coupon-title {
		width: 100%;
		font-size: 26rpx;
		color: #333;
		white-space: nowrap;
		overflow: hidden;
		text-overflow: ellipsis;
	}

	.tui-coupon-rule {
		padding-top: 22rpx;
	}

	.tui-rule-box {
		display: flex;
		align-items: center;
		transform: scale(0.8);
		transform-origin: 0 100%;
	}

	.tui-padding-btm {
		padding-bottom: 6rpx;
	}

	.tui-coupon-circle {
		width: 8rpx;
		height: 8rpx;
		background: rgb(160, 160, 160);
		border-radius: 50%;
	}

	.tui-coupon-text {
		font-size: 28rpx;
		line-height: 28rpx;
		font-weight: 400;
		color: #666;
		padding-left: 8rpx;
		white-space: nowrap;
	}

	.tui-top20 {
		margin-top: 20rpx;
	}

	.tui-coupon-title {
		font-size: 28rpx;
		line-height: 28rpx;
	}


	.tui-coupon-radio {
		transform: scale(0.7);
		transform-origin: 100% center;
	}

	.tui-btn-box {
		position: absolute;
		// width: 146rpx;
		height: 52rpx;
		right: 0rpx;
		bottom: 100rpx;
		z-index: 10;
	}

	/* #ifdef APP-PLUS || MP */
	.wx-radio-input {
		margin-right: 0 !important;
	}

	/* #endif */

	/* #ifdef H5 */
	>>>uni-radio .uni-radio-input {
		margin-right: 0 !important;
	}

	/* #endif */
</style>